﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;
using yunbo.Model.SM;
using yunbo.Repositorys.SMRepositorys;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace yunbo.Controllers.SMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class WMS_CKXXController : ControllerBase
    {
        WMS_CKXXRepository _wms_ckxxRepository = new WMS_CKXXRepository();
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="tjwms_ck"></param>
        /// <returns></returns>
        [HttpPost("PostWMS_CKXX")]
        public IActionResult PostWMS_CKXX(TJWMS_CKXX tjwmxx_ck)
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string id = $"ckxx{currentTime}{randomNumberString}";
            tjwmxx_ck.ckxx_code = id;
            bool rs = _wms_ckxxRepository.PostWMXX_CK(tjwmxx_ck) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="tjwms_ck"></param>
        /// <returns></returns>
        [HttpGet("GetWMXX_CK")]
        public IActionResult GetWMXX_CK(string code)
        {
                List<WMS_CKXX> wMS_CKXXes = _wms_ckxxRepository.GetWMXX_CK(code);
                return Ok(wMS_CKXXes);
        }
    }
}
